module.exports = (source) => {
  if (!String.prototype.localeCompare) return null

  const letters = '*abcdefghjklmnopqrstwxyz'.split('')
  // eslint-disable-next-line camelcase
  const zh_cn = '阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀'.split('')
  const totalList = []

  for (let i = 0; i < letters.length; i++) {
    const item = {
      name: letters[i],
      list: []
    }

    for (const val of source) {
      // eslint-disable-next-line eqeqeq
      if ((!zh_cn[i - 1] || zh_cn[i - 1].localeCompare(val) <= 0) && val.localeCompare(zh_cn[i]) == -1) {
        item.list.push(val)
      }
    }

    if (item.list.length) {
      item.list.sort(function (a, b) {
        return a.localeCompare(b)
      })
      totalList.push(item)
    }
  }
  return totalList
}
